<?php
namespace bee;
define("BEE_CHECK_HORIZONTAL", 1);
define("BEE_CHECK_VERTICAL", 2);
/**
 *
 * @author dzelenika
 * @todo nije završeno??? treba testirati
 *
 */
class checkGroup extends widget
{ public $values;
  public $labels;
  public $checks;
  public $orientation;
  private $events = array(	"onBlurFn", "onClickFn", "onDblClickFn",
  							"onKeyDownFn", "onKeyPressFn", "onKeyUpFn",
                "onMouseDownFn", "onMouseMoveFn", "onMouseOutFn", "onMouseOverFn", "onMouseUpFn");
/**
 * @todo bindValue bi trebao biti array
 * @param unknown_type $name
 * @param unknown_type $bindValue
 * @param array $options
 */
  function __construct($name, &$bindValue = "", array $options = array())
  { parent::__construct($name);
    $this->labels = isset($options["labels"]) ? $options["labels"] : array();
    $this->values = isset($options["values"]) ? $options["values"] : array();
    $this->bindValue($bindValue);    //
  }
 /**
  * @param array $evt
  */
  public function onDraw($evt)
  { foreach($this->checks as $cVal)
    { foreach ($this->events as $evt)
      { if($this->$evt)
        { $cVal->$evt = clone $this->$evt;
        }
      }
      //echo "<br /><br />$cVal->name" . print_r($cVal, true);
      //$cVal->checked();// ovaj kvari
      //echo "<br /><br />--$cVal->name" . print_r($cVal, true);
    }
    $this->fillDSDoc();
  }
  /**
   * @todo samo kopirao iz radija provjeriti radi li
   */
  public function setArrayLV($array, $append = false)
  { if(!$append)
    { $this->labels = array();
      $this->values = array();
    }
    foreach ($array as $key => $value)
    { $this->labels[] = $value;
      $this->values[] = $key;
    }
    $this->checks = array();
    foreach ($this->values as $cKey => &$cVal)
    { //$v = is_array($this->value) ? $this->value[$cKey] : $this->value;
      $v = $this->value[$cKey];
      $nc = new check($this->name, $v, $cVal, $this->name . "_" . $cVal);
      $nc->drawMe = false;
      $this->checks[] = $nc;
    }
  }

  public function bindValue(&$value)
  { $this->value = $value;
    $this->checks = array();
    foreach ($this->values as $cKey => &$cVal)
    { //$v = is_array($this->value) ? $this->value[$cKey] : $this->value;
      $v = $this->value[$cKey];
      $nc = new check($this->name, $v, $cVal, $this->name . "_" . $cVal);
      $nc->checked();
      $nc->drawMe = false;
      $this->checks[] = $nc;
    }
  }

 /**
  * @param sting $fillVar
  */
  public function fillDSDoc($fillVar = "")
  { if($fillVar)
    { $this->DSDoc->setVariable($fillVar, $this->value);
    }
    $this->DSDoc->setObject("widgets/" . $this->name, $this);
  }
}
